<?php

/**
 * WaterFeeTaskMsgtpl水费缴费消息模板
 *
 * @author hjc19850430@gmail.com
 */
class WaterFeeTaskMsgtpl extends BaseMsgtpl
{
	/**
	 * @param $wechat_id 公众号ID
	 * @param $subsidy_num 补贴吨数
	 */
	public function send($wechat_id, $subsidy_num)
	{
		$condition['WaterFeeList.wechat_id'] = $wechat_id;
		$condition['_string'] = 'student_num > 0 and (water_num-last_water_num) > student_num*' . $subsidy_num . ' and (WaterFeeList.order_id = 0 or (WaterFeeList.order_id > 0 and status != 1))';
		$list = D('WaterFeeListView')->getList($condition);
		$wechat = D('Wechat')->get($wechat_id);
		session('account_id', $wechat['account_id']);
		session('wechat_id', $wechat['wechat_id']);
		
		
		foreach($list as $key => $value) {
			if($value['fans_id'] > 0) {
				$fans = D('Fans')->get($value['fans_id'], 'openid,subscribe');
				
				if($fans['subscribe']) {
					$url = "http://alpha.wap.xt.beescrm.com/Base/waterFee/index/wechat_id/" . $wechat_id;

					if($wechat_id == 16) {
						$this->wxTplSign = 'jAN5P6cQn5stYDNptGitFEp4Gni0guRNVYrU-9QRCQw';
					} elseif($wechat_id == 14) {
						$this->wxTplSign = 'qvWPMbUULgzCtucu97wPWJCA_DK7PfEZaEIR9tt3hek';
					}
					
					$info = array(
						'first' => array("value" => '亲爱的同学，您的寝室水费超出啦', 'color' => '#173177'),
						'keyword1' => array("value" => '水费缴费预警', 'color' => '#173177'),
						'keyword2' => array("value" => date('Y-m-d H:i:s'), "color" => "#173177"),
						'remark' => array("value" => "速去缴费", "color" => "#173177")
					);
					
					$result = $this->wxObj->messageTpl($wechat['appid'], $wechat['appsecret'], $fans['openid'], $this->wxTplSign, $info, $url);
				}
			}
		}
		
	}
}
